<UserControl x:Class="Microsoft.EnhancedReminders.OutlookAddIn.NotificationRulesViewer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ds="clr-namespace:Microsoft.EnhancedReminders.OutlookAddIn"
    xmlns:properties="clr-namespace:Microsoft.EnhancedReminders.Properties"
    xmlns:common="clr-namespace:Microsoft.EnhancedReminders;assembly=Microsoft.EnhancedReminders.Common">

    <UserControl.Resources>
        <!-- The data source for populating the rules ListView. -->
        <ObjectDataProvider x:Key="RulesDataSource"
           ObjectType="{x:Type common:NotificationRules}"/>

        <!-- The checkbox for the "enable rule" column of the rules ListView -->
        <DataTemplate x:Key="EnableRule">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding Path=IsEnabled}" Command="{x:Static ds:NotificationRulesViewer.EnableRuleCommand}"/>
            </StackPanel>
        </DataTemplate>

        <!-- The checkbox to enable all rules (contained in the column header of the rules ListView). -->
        <DataTemplate x:Key="EnableAllRules">
            <StackPanel Orientation="Horizontal">
                <CheckBox Name="enableAllCheckbox" Command="{x:Static ds:NotificationRulesViewer.EnableAllRulesCommand}" Content="{x:Static properties:Resources.RulesDialogEnableAllCheckbox}"></CheckBox>
            </StackPanel>
        </DataTemplate>

        <Style x:Key="UpArrowStyle" TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True" >
                    <Setter Property="Source" Value="..\images\UpArrow.png"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Source" Value="..\images\UpArrowFaded.png"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="DownArrowStyle" TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Source" Value="..\images\DownArrow.png"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Source" Value="..\images\DownArrowFaded.png"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Thickness x:Key="ButtonSpacing">5,0,5,0</Thickness>
	
	</UserControl.Resources>

    <!-- Command bindings. -->
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.AddCommand}"
                    Executed="AddRule" CanExecute="AddCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.EditCommand}"
                    Executed="EditRule" CanExecute="EditAndDeleteCommandsCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.DeleteCommand}"
                    Executed="DeleteRule" CanExecute="EditAndDeleteCommandsCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.UpCommand}"
                    Executed="MoveRuleUp" CanExecute="UpCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.DownCommand}"
                    Executed="MoveRuleDown" CanExecute="DownCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.EnableRuleCommand}"
                    Executed="EnableRule" CanExecute="EnableRuleCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.EnableAllRulesCommand}"
                    Executed="EnableAllRules" CanExecute="EnableAllCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.OkCommand}"
                    Executed="ApplyAndClose" CanExecute="OkCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.CancelCommand}"
                    Executed="Cancel" CanExecute="CancelCommandCanExecute"/>
        <CommandBinding Command="{x:Static ds:NotificationRulesViewer.ApplyCommand}"
                    Executed="Apply" CanExecute="ApplyCommandCanExecute"/>
    </UserControl.CommandBindings>

    <!-- The outer container for the entire control. -->
    <StackPanel Name="stackPanel">

        <!-- 10-column grid container for the add/edit/delete/up/down buttons. -->
        <Grid FlowDirection="LeftToRight" Margin="20,20,20,20" Height="25" VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            
            <Button  Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,5,0" Name="addButton" Command="{x:Static ds:NotificationRulesViewer.AddCommand}" Content="{x:Static properties:Resources.RulesDialogAddButton}"></Button>
            <Button Grid.Column="2" Grid.ColumnSpan="2" Margin="{StaticResource ButtonSpacing}" Name="editButton" Command="{x:Static ds:NotificationRulesViewer.EditCommand}" CommandTarget="{Binding ElementName=listView1}" Content="{x:Static properties:Resources.RulesDialogEditButton}"></Button>
            <Button Grid.Column="4" Grid.ColumnSpan="2" Margin="{StaticResource ButtonSpacing}" Name="deleteButton" Command="{x:Static ds:NotificationRulesViewer.DeleteCommand}" Content="{x:Static properties:Resources.RulesDialogDeleteButton}"></Button>
            <Button Grid.Column="9" HorizontalAlignment="Left" Name="upButton" Command="{x:Static ds:NotificationRulesViewer.UpCommand}" >
                <Image Style="{StaticResource UpArrowStyle}" />
            </Button>
            <Button Grid.Column="9" HorizontalAlignment="Right" Name="downButton" Command="{x:Static ds:NotificationRulesViewer.DownCommand}" >
                <Image Style="{StaticResource DownArrowStyle}" />
            </Button>
        </Grid>

        <!-- The ListView to display the actual rules. -->
        <ListView Height="150" Margin="20,0,20,0" Name="rulesListView" MouseDoubleClick="rulesListView_MouseDoubleClick"
                  SelectionMode="Single" SelectionChanged="rulesListView_SelectionChanged"
                  ItemsSource="{Binding Source={StaticResource RulesDataSource}}">

            <ListView.View>

                <GridView AllowsColumnReorder="False">

                    <GridViewColumn HeaderTemplate="{StaticResource EnableAllRules}"
                                    CellTemplate="{StaticResource EnableRule}"/>

                    <GridViewColumn Header="{x:Static properties:Resources.RulesDialogNameHeader}"
                                    DisplayMemberBinding="{Binding Path=RuleName}"/>

                </GridView>

            </ListView.View>

        </ListView>

        <!-- Label for the rules description text box. -->
        <Label Height="25" Margin="20,20,20,0" VerticalAlignment="Bottom" Content="{x:Static properties:Resources.RulesDialogDescriptionLabel}"></Label>

        <!-- The rules description text box. -->
        <RichTextBox Height="85" Margin="20,0,20,25" Name="descriptionTextBox" VerticalAlignment="Bottom" IsReadOnly="True"/>

        <!-- 5-column container for the Ok/Cancel/Apply buttons. -->
        <Grid Margin="20,10,20,10" FlowDirection ="LeftToRight" Height="25">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
                <Button Grid.Column="2" Margin="0,0,5,0" Name="okButton" IsDefault="True" Command="{x:Static ds:NotificationRulesViewer.OkCommand}" Content="{x:Static properties:Resources.OkButton}" ></Button>
                <Button Grid.Column="3" Margin="{StaticResource ButtonSpacing}" Name="cancelButton" IsCancel="True" Command="{x:Static ds:NotificationRulesViewer.CancelCommand}" Content="{x:Static properties:Resources.CancelButton2}" ></Button>
                <Button Grid.Column="4" Margin="5,0,0,0" Name="applyButton" Command="{x:Static ds:NotificationRulesViewer.ApplyCommand}" Content="{x:Static properties:Resources.RulesDialogApplyButton}"></Button>
            </Grid>
            
        </StackPanel>
    
</UserControl>
